package com.sworm.batch.controller;

import com.sworm.batch.model.LoveBean;
import com.sworm.batch.model.PersonBean;
import com.sworm.batch.service.IPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private IPersonService personService;

    @RequestMapping("/addPerson/{name}")
    public PersonBean addPerson(@PathVariable("name")String name) {
        PersonBean person=new PersonBean();
        person.setName(name);
        return personService.addPerson(person);
    }

    @RequestMapping("/loves/{id1}/{id2}")
    public LoveBean loves(@PathVariable("id1")String id1, @PathVariable("id2")String id2){
        PersonBean person1=personService.findOnePerson(Long.parseLong(id1));
        PersonBean person2=personService.findOnePerson(Long.parseLong(id2));
        LoveBean love=new LoveBean();
        love.setStartNode(person1);
        love.setEndNode(person2);
        return personService.loves(love);
    }
}
